package cn.peach.hrm.util;

import cn.peach.hrm.constants.BaseConstants;
import cn.peach.hrm.exception.GlobalException;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

public class AssertUtil {

    /**
     * 断言对象为空
     * @param object
     * @param message
     */
    public static void isNull(Object object, String message) {
        if (object != null) {
            throw new GlobalException(message);
        }
    }

    /**
     * 断言对象不为空
     * @param object
     * @param message
     */
    public static void isNotNull(Object object, String message) {
        if (object == null) {
            throw new GlobalException(message);
        }
    }

    /**
     * 断言字符串不为空
     * @param object
     * @param message
     */
    public static void isNotEmpty(String str, String message) {
        if (!StringUtils.hasLength(str)) {
            throw new GlobalException(message);
        }
    }

    /**
     * 断言字符串为空
     * @param object
     * @param message
     */
    public static void isEmpty(String str, String message) {
        if (StringUtils.hasLength(str)) {
            throw new GlobalException(message);
        }
    }

    /**
     * 断言上线状态
     * @param status
     * @param statusOffLine
     * @param message
     */
    public static void isNotState(Integer st, int so, String message) {
        if (st != so) {
            throw new GlobalException(message);
        }
    }

    /**
     * 断言true
     * @param success
     * @param message
     */
    public static void isTrue(boolean success, String message) {
        if (!success) {
            throw new GlobalException(message);
        }
    }

    /**
     * 断言false
     * @param success
     * @param message
     */
    public static void isFalse(boolean success, String message) {
        if (success) {
            throw new GlobalException(message);
        }
    }

    /**
     * 断言两个int值相等
     */
    public static void isEquals(Integer i1, int i2, String message) {
        if(i1 != i2){
            throw new GlobalException(message);
        }
    }

    public static void isEqualsIgnoreCase(String i1, String i2, String message) {
        if(!i1.equalsIgnoreCase(i2)){
            throw new GlobalException(message);
        }
    }

    public static void isEqual(String i1, String i2, String message) {
        if(i1.equalsIgnoreCase(i2)){
            throw new GlobalException(message);
        }
    }
}

